<%--
  Created by IntelliJ IDEA.
  User: xianfei
  Date: 15-2-12
  Time: 下午2:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>短信</title>
    <style>
        .content {
            width: 400px;
        }
    </style>
    <script>
        $(function () {
            $("#submit").click(function () {
                var num = $(".phoneNum");
                var name = $(".username");
                var phoneNum = "";
                var username = "";
                var content = $("#message").val();
                for (var i = 0; i < num.length; i++) {
                    phoneNum += (i == num.length - 1) ? num.eq(i).val() : num.eq(i).val() + ',';
                }
                for (var i = 0; i < name.length; i++) {
                    username += (i == name.length - 1) ? name.eq(i).val() : name.eq(i).val() + ',';
                }
                $.ajax({
                    url:'/msg/send',
                    type:'POST',
                    data:{phoneNum:phoneNum,content:content,username:username},
                    success:function(data){
                        alert('发送成功');
                    },error:function(){
                        alert('error');
                    }
                })
            });

            $("#add").click(function () {
                var str = '<div class="content">姓名：<input type="text" class="username" value="">&nbsp;手机号码：<input type="text" class="phoneNum" value=""></div>';
                $(".content:last").after(str);
            });

            $("#del").click(function () {
                if ($(".content").length > 1) {
                    $(".content:last").remove();
                }
            });
        })
    </script>
</head>
<body>
<form>
    <input type="button" id="add" value="添加手机号码"/><input type="button" id="del" value="删除手机号码"><br/>

    <div class="content">
        姓名：<input type="text" class="username" value="">&nbsp;
        手机号码：<input type="text" class="phoneNum" value="">
    </div>
    <br/>短信内容：<textarea id="message"></textarea><br/>
    <input type="button" id="submit" value="发送"/>
</form>
</body>
</html>